let a = [1, 2, 3, 4, 5, 6]
let b = [3, 4, 5, 6, 7]

function extract(left, right) {
  let result = []
  if (left.length > right.length) {
    for (let item of left) {
      if (right.includes(item) && !result.includes(item)) {
        result.push(item)
      }
    }
  } else {
    for (let item of right) {
      if (left.includes(item) && !result.includes(item)) {
        result.push(item)
      }
    }
  }
  return result
}
